package com.quan.weixin.web.controller.boss;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.quan.base.common.base.web.support.BaseResult;
import com.quan.base.common.base.web.support.controller.BaseController;
import com.quan.base.common.utils.Paginator;
import com.quan.upms.annotation.RequiresPermissions;
import com.quan.weixin.rpc.api.WeixinTextService;
import com.quan.weixin.rpc.model.WeixinText;

@RestController
@RequestMapping(value = "/api/weixin/text")
public class WeixinTextController extends BaseController {

	@Autowired
	private WeixinTextService weixinTextService;

	@RequiresPermissions(value="weixin:text:add", description="添加微信文本消息")
	@PostMapping(value = "/add")
	public Object add(@Valid @RequestBody WeixinText entity, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
            return BaseResult.failure(bindingResult.getFieldError().getDefaultMessage()) ;
        }
		this.weixinTextService.insertSelective(entity);

		return BaseResult.ok();
	}

	@RequiresPermissions(value="weixin:text:delete", description="删除微信文本消息")
	@GetMapping(value = "/delete/{id}")
	public Object delete(@PathVariable Integer id) {
		this.weixinTextService.delete(id);
		return BaseResult.ok();
	}
	
	@RequiresPermissions(value="weixin:text:delete", description="删除微信文本消息")
	@GetMapping(value = "/deleteBatch")
	public Object deleteBatch(String ids) {
		this.weixinTextService.deleteByIds(ids) ;
		return BaseResult.ok();
	}

	@RequiresPermissions(value="weixin:text:update", description="修改微信文本消息")
	@PostMapping(value = "/update")
	public Object update(@Valid @RequestBody WeixinText entity, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
            return BaseResult.failure(bindingResult.getFieldError().getDefaultMessage()) ;
        }
		this.weixinTextService.update(entity);
		return BaseResult.ok();
	}

	@RequiresPermissions(value="weixin:text:detail", description="查询微信文本消息详情")
	@GetMapping(value = "/get/{id}")
	public Object list(@PathVariable Integer id) {
		return this.weixinTextService.selectById(id);
	}
	
	@RequiresPermissions(value="weixin:text:list", description="查询微信文本消息")
	@GetMapping(value = "/list")
	public Object list(WeixinText entity) {
		return this.weixinTextService.selectPage(new Paginator(request), entity) ;
	}
	
}
